/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * jFrDepositar.java
 *
 * Created on 08/10/2009, 15:28:54
 */

package jbanco;

import javax.swing.JOptionPane;


/**
 *
 * @author Cláudio
 */




public class jFrDepositar extends javax.swing.JDialog {
    private Boolean flag;
    private conta acc;
    /** Creates new form jFrDepositar */
    public conta getValor(){
        return acc;
    }
    public jFrDepositar(java.awt.Frame parent, boolean modal, conta p,boolean flag) {
        super(parent, modal);
        initComponents();
        jTextField.setDocument(new Doc());
        acc = p;
        this.flag = flag;
    }
   /*
    public void fmoeda(final JTextField formatomoeda){
        formatomoeda.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                double x = Double.parseDouble(formatomoeda.getText());
                DecimalFormat moneyFormat = new DecimalFormat("#,###,###.00");
                moneyFormat.setMaximumFractionDigits(3);
                moneyFormat.setMinimumFractionDigits(3);
                formatomoeda.setText(moneyFormat.format(x));
            }
        });

    }*/

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jTextField = new javax.swing.JTextField();
        jBtnConfirm = new javax.swing.JButton();
        jBtnCancel = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Informe o valor:", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Calibri", 0, 14))); // NOI18N

        jLabel1.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        jLabel1.setText("Valor em R$:");

        jTextField.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                jTextFieldFocusLost(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(10, 10, 10)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 187, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(35, 35, 35)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addContainerGap(41, Short.MAX_VALUE))
        );

        jBtnConfirm.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        jBtnConfirm.setIcon(new javax.swing.ImageIcon(getClass().getResource("/jbanco/Imagens/reviews_positive.gif"))); // NOI18N
        jBtnConfirm.setText("Confirmar");
        jBtnConfirm.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtnConfirmActionPerformed(evt);
            }
        });

        jBtnCancel.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        jBtnCancel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/jbanco/Imagens/reviews_negative.gif"))); // NOI18N
        jBtnCancel.setText("Cancelar");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jBtnConfirm, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jBtnCancel, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(28, 28, 28))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jBtnCancel, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jBtnConfirm, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jBtnConfirmActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtnConfirmActionPerformed
        // TODO add your handling code here:
        Confirmar();
        this.dispose();
    }//GEN-LAST:event_jBtnConfirmActionPerformed

    private void jTextFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTextFieldFocusLost


    }//GEN-LAST:event_jTextFieldFocusLost
    private void Confirmar(){
       if(flag){
           acc.setSaldo(acc.getSaldo()+Double.parseDouble(jTextField.getText()));
       }else{
           if(acc.getSaldo()-Double.parseDouble(jTextField.getText())>=0){
               acc.setSaldo(acc.getSaldo()-Double.parseDouble(jTextField.getText()));
           }else
               JOptionPane.showMessageDialog(this,"Saldo insuficiente","Erro",JOptionPane.ERROR_MESSAGE);
       
       }

    }
    /**
    * @param args the command line arguments
    */


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jBtnCancel;
    private javax.swing.JButton jBtnConfirm;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JTextField jTextField;
    // End of variables declaration//GEN-END:variables

}
